﻿using System;
using Android.App;
using Android.Content;
using Android.Util;
using Android.Widget;
using GBU.Services.Common;
using GBU.Services.LocationService;
using GBU.Services.StepService;

namespace GBU
{
    [Application]
    public class GlobalApplication : Application
    {
        public GlobalApplication(IntPtr handle, global::Android.Runtime.JniHandleOwnership transfer)
            : base(handle, transfer)
        {
            //Current = this;
        }

        private static CommonServiceConnection<AcceleraService> _acceleraServiceConnection;
        public static CommonServiceConnection<AcceleraService> AcceleraServiceConnection
        {
            get { return _acceleraServiceConnection; }
        }

        private static CommonServiceConnection<GpsService> _gpsServiceConnection;

        public static CommonServiceConnection<GpsService> GpsServiceConnection
        {
            get { return _gpsServiceConnection; }
        }

        public override void OnCreate()
        {
            Log.Debug(this.GetType().ToString(), "Application is Starting....");
            base.OnCreate();
            //启动计步器服务
            var demoServiceIntent = new Intent("AcceleraService");
            _acceleraServiceConnection = new CommonServiceConnection<AcceleraService>();
            ApplicationContext.BindService(demoServiceIntent, _acceleraServiceConnection, Bind.AutoCreate);
            StartService(demoServiceIntent);

            //启动gps服务
            var gpsServiceIntent = new Intent("GpsService");
            _gpsServiceConnection=new CommonServiceConnection<GpsService>();
            ApplicationContext.BindService(gpsServiceIntent, _gpsServiceConnection, Bind.AutoCreate);
            StartService(gpsServiceIntent);
            Toast.MakeText(this, "Service Started", ToastLength.Short).Show();
            //启动自动更新服务
            //启动
        }
    }
}
